<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:x="https://www.texmacs.org/2002/extensions" xmlns:m="http://www.w3.org/1998/Math/MathML">
  <head>
    <title>TeXmacs notes</title>
    <meta content="TeXmacs 1.99.18" name="generator"></meta>
    <link href="../resources/notes-base.css" type="text/css" rel="stylesheet"></link>
    <link href="../resources/blog-icon.png" rel="icon"></link>
    <script src="../resources/highlight.pack.js" language="javascript" defer></script>
    <script src="../resources/notes-base.js" language="javascript" defer></script>
  </head>
  <body>
    <div class="notes-header">
      <p>
        <img class="image" src="../resources/texmacs-blog-transparent.png" width="28.116784"></img><span style="margin-left: 2pt"></span><a href="./main.html">[main]</a><em
        class="notes-header-name">Notes on TeXmacs</em>
      </p>
    </div>
    <h1 id="auto-1">Customizing the color of code snippets<span style="margin-left: 1em"></span></h1>
    <p>
      By default, the preprocessor directives in <class style="font-variant: small-caps">C++</class>
      code snippets are rendered in green:
    </p>
    <div class="tmweb-code">
      <pre class="verbatim cpp" xml:space="preserve">
#include &quot;stdio.h&quot;</pre>
    </div>
    <p>
      It is controlled by the following preference:
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
(get-preference &quot;syntax:cpp:preprocessor_directive&quot;)</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <div class="compact-block" style="margin-top: 0.5em; margin-bottom: 0.5em; text-indent: 0em">
      <p style="margin-top: 0.5em; margin-bottom: 0.5em">
        <tt class="verbatim"><div style="margin-left: 42.175176192px">
          <div align="justify">
            &quot;dark green&quot;
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <p>
      And the preferences can be changed:
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
(set-preference &quot;syntax:cpp:preprocessor_directive&quot; &quot;black&quot;)</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <div class="compact-block" style="text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
(get-preference &quot;syntax:cpp:preprocessor_directive&quot;)</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <div class="compact-block" style="margin-top: 0.5em; margin-bottom: 0.5em; text-indent: 0em">
      <p style="margin-top: 0.5em; margin-bottom: 0.5em">
        <tt class="verbatim"><div style="margin-left: 42.175176192px">
          <div align="justify">
            &quot;black&quot;
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <p>
      Preferences are stored when we set it. For GNU TeXmacs v1.99.15, a
      re-render trigger (eg. Restart) is required for your changes to take
      effect.
    </p>
    <p>
      <div style="display: inline">
        <a id="auto-2"></a>
      </div>
      <h5>Decolorize<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      To decolorize all C++ code snippet, we need to know all the preferences
      for the C++ language. Some of them can be found in
      <tt>$TEXMACS_PATH/progs/prog/cpp-lang.scm</tt>. A complete list can be
      found at <a href="https://github.com/texmacs/texmacs/blob/a803cfbbf4a2e75e6621dbc2133f5da153b1c5d9/src/System/Language/language.cpp#L258">texmacs@v1.99.15:src/System/Language.cpp#L259</a>.
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
(map
 (lambda (key) (set-preference key &quot;black&quot;))
 (list
  &quot;syntax:cpp:comment&quot;
  &quot;syntax:cpp:keyword&quot;
  &quot;syntax:cpp:constant_string&quot;
  &quot;syntax:cpp:constant_number&quot;
  &quot;syntax:cpp:constant_type&quot;
  &quot;syntax:cpp:preprocessor_directive&quot;
  &quot;syntax:cpp:preprocessor&quot;
  &quot;syntax:cpp:error&quot;))</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <div class="compact-block" style="margin-top: 0.5em; margin-bottom: 0.5em; text-indent: 0em">
      <p style="margin-top: 0.5em; margin-bottom: 0.5em">
        <tt class="verbatim"><div style="margin-left: 42.175176192px">
          <div align="justify">
            (#&lt;unspecified&gt; #&lt;unspecified&gt; #&lt;unspecified&gt;
            #&lt;unspecified&gt; #&lt;unspecified&gt; #&lt;unspecified&gt;
            #&lt;unspecified&gt; #&lt;unspecified&gt;)
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <p>
      Restart TeXmacs or type some C++ code below to trigger recoloring:
    </p>
    <div class="tmweb-code">
      <pre class="verbatim cpp" xml:space="preserve">
#include &quot;stdio.h&quot;
int main() {
  return 0;
}</pre>
    </div>
    <p>
      <div style="display: inline">
        <a id="auto-3"></a>
      </div>
      <h5>Reset<span style="margin-left: 1em"></span></h5>
    </p>
    <p>
      To reset the colorizer:
    </p>
    <div class="compact-block" style="margin-top: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><pre class="verbatim" xml:space="preserve">
Scheme] </pre></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
(map
 (lambda (key) (reset-preference key))
 (list
  &quot;syntax:cpp:comment&quot;
  &quot;syntax:cpp:keyword&quot;
  &quot;syntax:cpp:constant_string&quot;
  &quot;syntax:cpp:constant_number&quot;
  &quot;syntax:cpp:constant_type&quot;
  &quot;syntax:cpp:preprocessor_directive&quot;
  &quot;syntax:cpp:preprocessor&quot;
  &quot;syntax:cpp:error&quot;))</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <div class="compact-block" style="margin-top: 0.5em; margin-bottom: 0.5em; text-indent: 0em">
      <p style="margin-top: 0.5em; margin-bottom: 0.5em">
        <tt class="verbatim"><div style="margin-left: 42.175176192px">
          <div align="justify">
            (#&lt;unspecified&gt; #&lt;unspecified&gt; #&lt;unspecified&gt;
            #&lt;unspecified&gt; #&lt;unspecified&gt; #&lt;unspecified&gt;
            #&lt;unspecified&gt; #&lt;unspecified&gt;)
          </div>
        </div></tt>
      </p>
    </div>
    <div class="compact-block" style="margin-bottom: 0.5em; text-indent: 0em">
      <table style="width: 100%">
        <tbody><tr>
          <td style="padding-left: 0em; padding-right: 0em"><font color="#008000"><tt class="verbatim">Scheme] </tt></font></td>
          <td style="width: 100%; padding-left: 0em; padding-right: 0em"><font color="black"><pre class="verbatim" xml:space="preserve">
</pre></font></td>
        </tr></tbody>
      </table>
    </div>
    <p>
      Restart TeXmacs or type something below to see the effects:
    </p>
    <div class="tmweb-code">
      <pre class="verbatim cpp" xml:space="preserve">
#include &quot;stdio.h&quot;
int main() {
  return 0;
}</pre>
    </div>
  </body>
</html>